home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 November
/
PCWorld_2006-11_cd.bin
/
domacnost a kancelar
/
findgraph
/
fgraph.exe
/
{app}
/
TestApprVB
/
Form1.frm
< prev
next >
Wrap
Text File
|
2006-05-23
|
25KB
|
869 lines
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
Caption = "FindGraph automation, Fitting"
ClientHeight = 6840
ClientLeft = 7365
ClientTop = 345
ClientWidth = 6420
LinkTopic = "Form1"
ScaleHeight = 6840
ScaleWidth = 6420
Begin VB.CommandButton BSpline
Caption = "B-Spline"
Height = 495
Left = 4920
Picture = "Form1.frx":0000
Style = 1 'Graphical
TabIndex = 14
ToolTipText = "Nonlinear models"
Top = 5760
Width = 1455
End
Begin VB.CommandButton Regression
Caption = "Regression"
Height = 495
Left = 4920
Picture = "Form1.frx":05E2
Style = 1 'Graphical
TabIndex = 13
ToolTipText = "Nonlinear models"
Top = 5160
Width = 1455
End
Begin VB.CommandButton User
Caption = "User"
Height = 495
Left = 4920
Picture = "Form1.frx":0BC4
Style = 1 'Graphical
TabIndex = 10
ToolTipText = "User defined DLL"
Top = 4545
Width = 1455
End
Begin VB.CommandButton Curve
Caption = "Piece"
Height = 495
Left = 4920
Picture = "Form1.frx":11A6
Style = 1 'Graphical
TabIndex = 9
ToolTipText = "Piece Linear"
Top = 1475
Width = 1455
End
Begin VB.CommandButton Nonlinear
Caption = "Nonlinear"
Height = 495
Left = 4920
Picture = "Form1.frx":1788
Style = 1 'Graphical
TabIndex = 8
ToolTipText = "Nonlinear models"
Top = 3931
Width = 1455
End
Begin VB.CommandButton Neural
Caption = "Neural"
Height = 495
Left = 4920
Picture = "Form1.frx":1D6A
Style = 1 'Graphical
TabIndex = 7
ToolTipText = "Neural network approximation"
Top = 3317
Width = 1455
End
Begin VB.CommandButton Fourie
Caption = "Fourie"
Height = 495
Left = 4920
Picture = "Form1.frx":234C
Style = 1 'Graphical
TabIndex = 6
ToolTipText = "Fourie line"
Top = 2703
Width = 1455
End
Begin VB.CommandButton Logistic
Caption = "Logistic"
Height = 495
Left = 4920
Picture = "Form1.frx":292E
Style = 1 'Graphical
TabIndex = 5
ToolTipText = "Logistic model"
Top = 2089
Width = 1455
End
Begin VB.CommandButton Polynomial
Caption = "Polynomial"
Height = 516
Left = 4920
Picture = "Form1.frx":2F10
Style = 1 'Graphical
TabIndex = 0
ToolTipText = "Fit regression line"
Top = 840
Width = 1452
End
Begin MSComctlLib.ListView ListView1
Height = 1215
Left = 240
TabIndex = 1
Top = 4920
Width = 4575
_ExtentX = 8070
_ExtentY = 2143
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin MSComctlLib.ListView ListView2
Height = 3975
Left = 240
TabIndex = 11
Top = 840
Width = 4575
_ExtentX = 8070
_ExtentY = 7011
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin VB.Label ErrInf
Caption = "1"
Height = 375
Left = 4920
TabIndex = 12
Top = 6240
Width = 1335
End
Begin VB.Label FunctionName
Height = 615
Left = 120
TabIndex = 4
Top = 120
Width = 6255
WordWrap = -1 'True
End
Begin VB.Label Deviation
Caption = "0.0001"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 204
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1200
TabIndex = 3
Top = 6240
Width = 3495
End
Begin VB.Label Label1
Caption = "Deviation"
Height = 255
Left = 120
TabIndex = 2
Top = 6240
Width = 855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetModuleFileName Lib "kernel32" _
Alias "GetModuleFileNameA" _
(ByVal hModule As Long, _
ByVal lpFileName As String, _
ByVal nSize As Long) As Long
Dim FindGraph As Object
Sub LogError()
'Print "error " & Err.Description
ErrInf.Caption = Err.Description
End Sub
Private Sub Command1_Click()
End Sub
Private Sub Form_Load()
On Error GoTo ErrHandler
' Create object FindGraph
Set FindGraph = CreateObject("FindGraph.Document")
' Run program FindGraph in new window
FindGraph.AppInit (1) ' 1 - visible, 0 - hiddden
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo ErrHandler
' Close FindGraph application
FindGraph.AppQuit
ErrHandler:
Set FindGraph = Nothing
End Sub
Private Sub ListInit()
ListView1.ListItems.Clear
nw1 = ListView1.Width / 5
nw2 = ListView1.Width * 3 / 4
ListView1.ColumnHeaders.Add , , " ", nw1
ListView1.ColumnHeaders.Add , , "Coeff", nw2
' Dim Col As ColumnHeader ' Declare variable
' Set Col = ListView1.ColumnHeaders.Add , , " ", ListView1.Width / 5
' Set Col = ListView1.ColumnHeaders.Add , , "Coeff", ListView1.Width * 3 / 4
End Sub
Private Sub ListAdd(i, Coef)
Dim Insert As ListItem
Set Insert = ListView1.ListItems.Add(, , CStr(i))
Insert.SubItems(1) = CStr(Coef)
End Sub
Private Sub ShowResults()
FunctionName.Caption = FindGraph.FuncApprString
NGet = FindGraph.ApprParamsNumber
Deviation.Caption = FindGraph.GetApprParam(NGet - 1)
' Print "ub"; UBound(vaCoef)
' Fill the grid with coefficients
ListInit
Dim fCoef As Double
For i = 1 To NGet - 1
fCoef = FindGraph.GetApprParam(i - 1)
ListAdd i, fCoef
Next i
End Sub
Private Sub ShowResultsVariant()
FunctionName.Caption = FindGraph.FuncApprString
Dim vaCoef As Variant
vaCoef = FindGraph.ArrayParams
NGet = UBound(vaCoef)
Deviation.Caption = vaCoef(NGet - 1)
' Print "ub"; UBound(vaCoef)
' Fill the grid with coefficients
ListInit
Dim fCoef As Double
For i = 1 To NGet - 1
fCoef = vaCoef(i - 1)
ListAdd i, fCoef
Next i
End Sub
Private Sub List2Init()
ListView2.ListItems.Clear
Dim Col As ColumnHeader ' Declare variable
Set Col = ListView2.ColumnHeaders.Add(, , " ", ListView1.Width / 6)
Set Col = ListView2.ColumnHeaders.Add(, , "X", ListView1.Width / 4)
Set Col = ListView2.ColumnHeaders.Add(, , "Y", ListView1.Width / 4)
Set Col = ListView2.ColumnHeaders.Add(, , "Yappr", ListView1.Width / 4)
End Sub
Private Sub List2Add(i, x, y0, y1)
Dim Insert As ListItem
Set Insert = ListView2.ListItems.Add(, , CStr(i))
Insert.SubItems(1) = CStr(x)
Insert.SubItems(2) = CStr(y0)
Insert.SubItems(3) = CStr(y1)
End Sub
Private Sub ShowDataVals(dwId, N, vaDots)
' Fill the grid with Data
List2Init
Dim x, y0, y1 As Double
For i = 1 To N
it = (i - 1) * 3
x = vaDots(it)
y0 = vaDots(it + 1)
'y1 = vaDots(it + 2)
' You can calculate value
y1 = FindGraph.FuncApprInPoint(dwId, x)
List2Add i, x, y0, y1
Next i
End Sub
Private Sub ShowData(dwId)
Dim vaDots As Variant
vaDots = FindGraph.ArrayVar
NGet = UBound(vaDots)
'Print "ub"; UBound(vaDots)
' Fill the grid with Data
List2Init
N = NGet / 3
Dim x, y0, y1 As Double
For i = 1 To N
it = (i - 1) * 3
x = vaDots(it)
y0 = vaDots(it + 1)
' FindGraph fills vaDots column Z with calculated values
y1 = vaDots(it + 2)
' Alternatively you can calculate value
' y1 = FindGraph.FuncApprInPoint(dwId, x)
List2Add i, x, y0, y1
Next i
End Sub
' The examples show how to fit data
' Create new function named "Polynomial"
Private Sub Polynomial_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 100
Dim vaDots(300) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(1, 2, 20, 1, "Polynomial")
' Weighting
' 0 No weight, Wi = 1
' 1 Statistical, Wi = 1/Yi
' 2 Statistical, Wi = Yi
' 3 Statistical, Wi = 1/Xi
' 4 Statistical, Wi = Xi
' 5 Instrumental, Wi = 1/Zi^2
' 6 Direct, Wi = Zi
FindGraph.Weighting = 0
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(4# + 3 * Sin(3 / N * i))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 0 'Polynomial
Dim vaParams(10) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(3) ' nOrder for regression line or 0
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
dwFunc = FindGraph.FuncApprCreate(3, 10, "Polynomial")
ShowDataVals dwFunc, N, vaDots
' ShowData (dwFunc)
ShowResults
ErrInf.Caption = "Done"
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub Logistic_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 100
Dim vaDots(300) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(2, 2, 20, 1, "Logistic")
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(1# + 4 * Sin(2 / N * i - 0.3))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 50 'Logistic
Dim vaParams(10) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(3) ' nOrder for regression line or 0
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
dwFunc = FindGraph.FuncApprCreate(3, 10, "Logistic")
ShowDataVals dwFunc, N, vaDots
ShowResults
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub Fourie_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 100
Dim vaDots(300) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(3, 2, 20, 1, "Fourie")
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(4# + 3 * Sin(10 / N * i))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 60 'Fourie
Dim vaParams(10) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(3) ' number of harmonics
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
dwFunc = FindGraph.FuncApprCreate(3, 10, "Fourie")
ShowDataVals dwFunc, N, vaDots
ShowResults
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
'Piece linear
Private Sub Curve_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 100
Dim vaDots(300) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(3, 2, 20, 1, "Piece linear")
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(4# + 3 * Sin(10 / N * i))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 20 'Fourie
Dim vaParams(10) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(20) ' Number of steps
vaParams(2) = CDbl(0) ' If 1 - lines on centers of steps
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
dwFunc = FindGraph.FuncApprCreate(3, 10, "Piece linear")
ShowDataVals dwFunc, N, vaDots
ShowResults
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
' It may be very SLOW
Private Sub Neural_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 20
Dim vaDots(60) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(4, 2, 20, 1, "Neural")
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(1# + 4 * Sin(2 / N * i - 0.3))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 70 'Neural network approximation
Dim vaParams(10) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(8) ' Number of neurons
vaParams(2) = CDbl(4) ' Parameter A
vaParams(3) = CDbl(0.0001) ' Step
vaParams(4) = CDbl(1000) ' Maximum number of iterations
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
dwFunc = FindGraph.FuncApprCreate(4, 10, "Neural")
ShowDataVals dwFunc, N, vaDots
ShowResults
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub Nonlinear_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 20
Dim vaDots(60) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(4, 2, 20, 1, "Nonlinear")
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(1# + 4 * Sin(2 / N * i - 0.3))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 88 ' Non-linear (predefined function)
Dim vaParams(20) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(1) ' Unused, must be > 0
vaParams(2) = CDbl(1060) ' Fitting curve Equation, parabola+sqrt for example
vaParams(3) = CDbl(1000) ' Fitting Model, polynomial for example
vaParams(4) = CDbl(0.0001) ' Step
vaParams(5) = CDbl(1000) ' Number of Iterations
vaParams(6) = CDbl(0) ' Model, 0 - Simplex, 1 - Gradient
vaParams(7) = CDbl(0) ' If > 0 - Normalize X
vaParams(8) = CDbl(0) ' Initial value of parameter A
vaParams(9) = CDbl(0.5) ' Initial value of parameter B
vaParams(10) = CDbl(0.5) ' Initial value of parameter C
vaParams(11) = CDbl(0) ' Initial value of parameter D
vaParams(12) = CDbl(0) ' Initial value of parameter G
vaParams(13) = CDbl(0) ' If > 0 Fixed parameter A
vaParams(14) = CDbl(0) ' If > 0 Fixed parameter B
vaParams(15) = CDbl(0) ' If > 0 Fixed parameter C
vaParams(16) = CDbl(0) ' If > 0 Fixed parameter D
'Uncomment it to set your own formula
'Pay attention, the calculation may be VERY SLOW
'nIdFunc = 90 ' Non-linear (formula)
'FindGraph.FuncApprString = "a+b*u+c*u*u+d*sin(u)"
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
dwFunc = FindGraph.FuncApprCreate(4, 10, "Nonlinear")
ShowDataVals dwFunc, N, vaDots
ShowResults
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub Regression_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 20
Dim vaDots(60) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(4, 2, 20, 1, "Regression")
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(1# + 4 * Sin(2 / N * i - 0.3))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 10 ' Linear Regression
NParams = 72
Dim vaParams(73) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(1) ' Unused, must be > 0
For i = 2 To NParams
vaParams(i) = CDbl(0)
Next i
' Polynomial
N1 = 2 'V(U) = V0 + a11*(U-U1)/W1 + a12*((U-U1)/W1)^2 + ...
vaParams(N1 + 0) = CDbl(0) ' U1
vaParams(N1 + 1) = CDbl(1) ' W1
vaParams(N1 + 2) = CDbl(1) ' If > 0 use V0 (const)
vaParams(N1 + 3) = CDbl(1) ' If > 0 use a11*U
vaParams(N1 + 4) = CDbl(1) ' If > 0 use a12*U^2
vaParams(N1 + 5) = CDbl(1) ' If > 0 use a13*U^3
vaParams(N1 + 6) = CDbl(1) ' If > 0 use a14*U^4
N2 = 12 'V(U) =... + a21*W2/(U-U2) + a22*(W2/(U-U2))^2 + ...
vaParams(N2 + 0) = CDbl(0) ' U2
vaParams(N2 + 1) = CDbl(1) ' W2
vaParams(N2 + 3) = CDbl(1) ' If > 0 use a21*W2/(U-U2)
N3 = 22 'V(U) =... + a31*sqr((U-U3)/W3) + a32/sqr((U-U3)/W3) + ...
N4 = 32 'V(U) =... + a41*ln (U-U4)/W4 + a42* (ln((U-U4)/W4)^2 + ...
N5 = 42 'V(U) =... + a51*exp(U-U5)/W5 + a52* exp(2*(U-U5)/W5) + ...
N6 = 52 'V(U) =... + a61*sin(U-U6)/W6 + a62* sin(2*(U-U6)/W6) + ...
N7 = 62 'V(U) =... + a71*cos(U-U6)/W6 + a72* cos(2*(U-U7)/W6) + ...
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
dwFunc = FindGraph.FuncApprCreate(4, 10, "Regression")
ShowDataVals dwFunc, N, vaDots
ShowResults
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub User_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 20
Dim vaDots(60) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(4, 2, 20, 1, "User DLL")
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(1# + 4 * Sin(2 / N * i - 0.3))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 80 ' User defined Plug-In DLL
Dim vaParams(20) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(1) ' Unused, must be > 0
vaParams(2) = CDbl(0) ' Parameter 1
vaParams(3) = CDbl(1) ' Parameter 2
vaParams(4) = CDbl(0) ' Parameter 3
vaParams(5) = CDbl(0) ' Parameter 4
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
FindGraph.FuncApprString = "fit_exp.dll"
dwFunc = FindGraph.FuncApprCreate(5, 10, "User DLL")
ShowDataVals dwFunc, N, vaDots
ShowResults
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub BSpline_Click()
On Error GoTo ErrHandler
Dim dwDots, dwFunc, it, N As Long
Dim nIdFunc As Long
Dim fX, fY, fZ As Double
N = 20
Dim vaDots(60) As Variant
' Create new series of points
dwDots = FindGraph.DotsNew(4, 2, 20, 1, "User DLL")
' Set the identifier of a series
FindGraph.ArrayId = dwDots
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(1# + 4 * Sin(2 / N * i - 0.3))
fZ = CDbl(i)
it = (i - 1) * 3
vaDots(it) = fX
vaDots(it + 1) = fY
vaDots(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = vaDots
' Approximation
nIdFunc = 32 ' B-spline
Dim vaParams(20) As Variant ' parameters for automation approximation
vaParams(0) = CDbl(0) ' 0 - y=f(x), 1 - x=f(y)
vaParams(1) = CDbl(1) ' Unused, must be > 0
vaParams(2) = CDbl(0) ' Unused
vaParams(3) = CDbl(0) ' 0 - approximation, 1 - interpolation
vaParams(4) = CDbl(0) ' 1 - closed curve
vaParams(5) = CDbl(12) ' number of control points: 1-12
vaParams(6) = CDbl(3) ' Degree: 1-6
FindGraph.FuncApprStart (nIdFunc)
FindGraph.ArrayVar = vaDots
FindGraph.ArrayParams = vaParams
FindGraph.FuncApprString = "fit_exp.dll"
dwFunc = FindGraph.FuncApprCreate(5, 10, "B-Spline")
ShowDataVals dwFunc, N, vaDots
ShowResults
FindGraph.FuncApprEnd
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub